package ihis.core.report;

import ihis.core.db.IHISDatabase;
import ihis.model.GeneralFilter;
import ihis.model.IHISConstants;
import ihis.model.Performance;
import ihis.model.PerformanceReport;
import ihis.model.Report;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class PerformanceReportFactory extends ReportFactory {

	/* (non-Javadoc)
	 * @see ihis.core.report.ReportFactory#getReport(ihis.model.GeneralFilter)
	 */
	@Override
	public Report getReport(GeneralFilter filter) {
		PerformanceReport report = new PerformanceReport();
		
	    try {
	    	List<Performance> performanceList = null;
			if(filter.getOwnerType() == IHISConstants.OWNERTYPE_PERSON ){
				performanceList = (ArrayList<Performance>) IHISDatabase.getSqlMapClient().queryForList("SelectList.PersonalPerformance", filter);
			}
			else if(filter.getOwnerType() == IHISConstants.OWNERTYPE_TEAM){
				performanceList = (ArrayList<Performance>) IHISDatabase.getSqlMapClient().queryForList("SelectList.TeamPerformance", filter);
			}
			
			if(performanceList == null){
				return report;
			}
			
			report.setPerformanceList(performanceList);
			
			report.setFilter(filter);
			
	    } catch (SQLException e) {
			e.printStackTrace();
		}
		
		return report;
	}

}
